<template>
  <!-- 任务书 -->
  <div>
    <!-- 标题区域 -->
    <div class="title">
      <el-descriptions :column="3" border>
        <el-descriptions-item label="我的毕业设计课题">
          <router-link to="/mytopic">{{ topic }}</router-link>
        </el-descriptions-item>
        <el-descriptions-item label="指导老师">
          <router-link
            :to="{ path: '/teacherinfo', query: { id: teacher_id } }"
            >{{ teacher }}</router-link
          >
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <!-- 内容区域 -->
    <div class="content">
      <el-descriptions :column="3" border>
        <el-descriptions-item label="任务书结束时间">无 </el-descriptions-item>
        <el-descriptions-item label="我的任务书">
          <a href="javascript:;" @click="download()">{{ task.title }}</a>
        </el-descriptions-item>
      </el-descriptions>
    </div>
  </div>
</template>
<script>
export default {
  created() {
    this.getTask();
    this.choose_task();
  },
  data() {
    return {
      teacher_id: "",
      teacher: "",
      topic: "",
      task: "",
    };
  },
  methods: {
    getTask() {
      this.$http.get("http://127.0.0.1:8080/my/getTopic").then((res) => {
        // console.log(res.data.data);
        // console.log(res.data.data[1][0].topic_name);
        // console.log(this.topic);
        if (res.data.status == 0) {
          this.topic = res.data.data[1][0].topic_name;
          this.teacher = res.data.data[0][0].teacher_name;
          this.teacher_id = res.data.data[0][0].id;
        } else {
          (this.topic = ""), (this.teacher = "");
        }
      });
    },
    choose_task() {
      this.$http.get("http://127.0.0.1:8080/my/choose_task").then((res) => {
        // console.log(res);
        if (res.data.status == 0) {
          this.task = res.data.data[0];
        } else {
          this.task = "";
        }
        // console.log(this.task.id);
      });
    },
    download() {
      location.href = "http://127.0.0.1:8080/api/download_1?id=" + this.task.id;
    },
  },
};
</script>
<style lang="less" scoped>
.content {
  margin: 20px 0;
}
</style>
